package business_logic;


import java.util.HashMap;
import java.util.Map;

import business_logic.view.*;

public class GameViewFactory
{
    
    private final static Class<? extends GameView> m_defaultViewClass = UnknownView.class;
    private final static Map<GameViewIdentifier,Class<? extends GameView>> m_dictionary;
    
    static
    {
        
        m_dictionary = new HashMap<GameViewIdentifier,Class<? extends GameView>>();
        
        // Inicializo el diccionario.
        
        m_dictionary.put(GameViewIdentifier.SPRITE_BLOQUE_DE_ACERO,BloqueAceroView.class);
        m_dictionary.put(GameViewIdentifier.SPRITE_BLOQUE_DE_CEMENTO,BloqueCementoView.class);
        m_dictionary.put(GameViewIdentifier.SPRITE_BLOQUE_DE_LADRILLOS,BloqueLadrillosView.class);
        m_dictionary.put(GameViewIdentifier.SPRITE_CECILIO,CecilioView.class);
        m_dictionary.put(GameViewIdentifier.SPRITE_LOPEZ_REGGAE,LopezReggaeView.class);
        m_dictionary.put(GameViewIdentifier.SPRITE_LOPEZ_REGGAE_ALADO,LopezReggaeAladoView.class);
        m_dictionary.put(GameViewIdentifier.SPRITE_PROYECTIL,ProjectileView.class);
        m_dictionary.put(GameViewIdentifier.SPRITE_UPGRADE_TOLETOLE,UpgradeToleToleView.class);  
        m_dictionary.put(GameViewIdentifier.SPRITE_TOLETOLE,ToleToleView.class);
        m_dictionary.put(GameViewIdentifier.SPRITE_UPGRADE_TIMER,UpgradeTimerView.class);
        m_dictionary.put(GameViewIdentifier.SPRITE_BOMBITA_RODRIGUEZ,BombitaView.class);
        m_dictionary.put(GameViewIdentifier.SPRITE_MOLOTOV,MolotovView.class);
        m_dictionary.put(GameViewIdentifier.SPRITE_EXPLOSION,ExplosionView.class);
        m_dictionary.put(GameViewIdentifier.SPRITE_UPGRADE_CHALA,ChalaView.class);
        m_dictionary.put(GameViewIdentifier.SPRITE_PORTAL,PortalView.class);
        m_dictionary.put(GameViewIdentifier.CHEAT_DROP,DropCheat.class);
        
    }
    
    public GameView createViewForGameElement( GameViewIdentifier gameElementViewId, Observable gameElement )
    {

        GameView view = null;
        
        // Obtengo la clase de la vista a construir.
        try
        {
            Class<? extends GameView> viewClass = m_dictionary.get(gameElementViewId);    
            view = viewClass.getDeclaredConstructor(Observable.class).newInstance(gameElement);
        }
        catch ( Exception e )
        {
            try
            {
                view = m_defaultViewClass.getDeclaredConstructor(Observable.class).newInstance(gameElement);
            }
            catch ( Exception e2 )
            {
                e2.printStackTrace();
            }
        }
        
        return view;
    }
    
}